package LeetCode.leetcode977;

public class Review3 {
    public int[] sortedSquares(int[] nums) {
        int[] res = new int[nums.length];
        int[] tmp = new int[nums.length];
        int l = 0;
        int r = tmp.length - 1;
        int k = res.length - 1;
        for (int i = 0; i < tmp.length; i++) {
            tmp[i] = nums[i] * nums[i];
        }
        while (l <= r){
            if (tmp[l] < tmp[r]){
                res[k--] = tmp[r--];
            }else {
                res[k--] = tmp[l++];
            }
        }
        return res;
    }
}
